package cn.com.greatwall.system.modules.oauth2.service;

import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.stereotype.Service;

import cn.com.greatwall.system.modules.oauth2.service.dto.JwtClientDto;
import cn.com.greatwall.system.modules.oauth2.service.dto.OauthClientDetailsDto;
import cn.com.greatwall.system.modules.security.config.bean.LoginProperties;
import cn.com.greatwall.system.modules.security.service.dto.JwtUserDto;
import cn.com.greatwall.system.modules.system.service.DataService;
import cn.com.greatwall.system.modules.system.service.RoleService;
import cn.com.greatwall.system.modules.system.service.UserService;
import lombok.RequiredArgsConstructor;

/**
 * @Author herw
 * @Time 2020-12-09 16:29:42
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
@RequiredArgsConstructor
@Service
public class ClientDetailsServiceImpl implements ClientDetailsService {
    private final OauthClientDetailsService oauthClientDetailsService;
    private final RoleService roleService;
    private final DataService dataService;

    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        JwtClientDto jwtClientDto = null;
        OauthClientDetailsDto client = oauthClientDetailsService.findById(clientId);
        if (client == null) {
            throw new ClientRegistrationException("客户端不存在");
        }
        jwtClientDto = new JwtClientDto(client, null, null);
        
        return jwtClientDto;
    }

}
